package com.lu.controller;

import com.lu.entity.Student;
import com.lu.service.student.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    //查询全部学生的数据，返回给前端
    @GetMapping("/student")
    public List<Student> getStudents(Integer currentPage, Integer pageSize) {
        log.info("页码，{},{}", currentPage, pageSize);
        return studentService.getStudents(currentPage, pageSize);
    }

    //根据id删除学生数据
    @DeleteMapping("/deleteStudent/{id}")
    public void deleteStudent(@PathVariable Integer id) {
        log.info("delete student id:{}", id);
        studentService.deleteStudent(id);
    }

    //根据id查询学生数据
    @GetMapping("/getStudentsById")
    public List<Student> getStudentById(@RequestParam Integer id) {
        return studentService.getStudentsById(id);
    }

    //修改学生数据
    @PutMapping("/updateStudent")
    public void updateStudent(@RequestBody Student student) {
        studentService.updateStudent(student);
    }

    //添加学生数据
    @PostMapping("/insertStudentData")
    public void insertStudentData(@RequestBody Student student) {
        studentService.insertStudent(student);
    }

    //根据传入的学号和姓名查询对应的数据
    @PostMapping("/getStudentByStdName")
    public List<Student> getStudentByStdName(@RequestBody Student student) {
        return studentService.getStudentsByStdName(student);
    }
}
